package com.gnerv.sylvanas.module.redis;

import com.gnerv.sylvanas.module.redis.autoconfigure.DynamicRedisRoutingDataSource;
import lombok.Setter;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @author ligen
 */
@Setter
public class RedisTemplatePlus<T, V> extends RedisTemplate<T, V> {

    private DynamicRedisRoutingDataSource dynamicRedisRoutingDataSource;

    @Override
    public RedisConnectionFactory getRequiredConnectionFactory() {
        RedisConnectionFactory connectionFactory = dynamicRedisRoutingDataSource.determineDataSource();
        return connectionFactory == null ? super.getRequiredConnectionFactory() : connectionFactory;
    }

}
